
<script type="text/javascript">
$(document).ready(function () {$smarty.ldelim}
	$('#btnAddOperator').click( function() {$smarty.ldelim}
		var operatorId = $("#selOperator").val();
		if(!operatorId)
			return;
		
		var row = $("#rowOp"+operatorId);
		row.clone().insertAfter('#tblWorkCount > tbody:last');
		row.remove();
		$("#rowOp"+operatorId).show();
		
		
		$("#selOp"+operatorId).remove();
	{$smarty.rdelim});
	
	
	$('.textWorkCount').blur(function () {$smarty.ldelim}
		var newValue = parseInt($(this).val());
		var oldValue = parseInt($(this).attr('data-currentValue'));
		if(newValue != oldValue) {$smarty.ldelim}
			var operationId = $(this).attr('data-operationId');
			
			var oldTotal = parseInt($("#total"+operationId).text());
			$("#total"+operationId).text(oldTotal + (newValue - oldValue));
			
			$(this).attr('data-currentValue', newValue);
		{$smarty.rdelim}
	{$smarty.rdelim});
	
{$smarty.rdelim});
</script>


						<h1 align="center">Заработка за Модел</h1>

					
						<form name="formModel" action="{$smarty.server.PHP_SELF}" method="post">
							<table cellspacing="0" cellpadding="2">
								<tr>
									<td colspan="3"><h3><b>Добавяне на Оператор</h3></b></td>
								</tr>
								<tr>
									<td>Оператори</td>
									
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td>
										<select id="selOperator" name="selOperator" >
											<option value="0">Избери</option>
										{foreach from=$operators key=operatorId item=opName}
											<option id="selOp{$operatorId}" value="{$operatorId}">{'cp1251'|iconv:'utf-8':$opName}</option>
										{/foreach}
										</select>
									</td>
									<td><input id="btnAddOperator" type="button" name="sub_model" value="Добави" /></td>
								</tr>
							</table>
						</form>

						
						
						
						
						<br /><br /><br />

						<table cellspacing="0" width="100%">
							<tr>
								<td class="DialogTitle">Модел: {'cp1251'|iconv:'utf-8':$model->name()}</td>
							</tr>
							<tr>
								<td class="DialogBorder">

									<div style="margin: 10px 0 10px 20px;">Дата: {$dateEdit}</div>
									<form name="vsdeDate" action="{$smarty.server.PHP_SELF}?{$smarty.server.QUERY_STRING}" method="post">
										<input type="hidden" name="date" id="date" value="{$vsdeDate}" />
									</form>
									
								
									<table cellspacing="1" class="DialogBox">
										<tr>
											<td class="DialogBox" valign="top"><br />
											{if empty($listOperations)}
												Няма въведени операции за модела.

											{else}
												<form action="{$smarty.server.PHP_SELF}?{$smarty.server.QUERY_STRING}" method="post" name="processcategoryform">
													<input type="hidden" name="modelId" value="{$model->id()}" />
													<input type="hidden" name="date" value="{$vsdeDate}" />
													
													<div id="boxTblWorkCount">
													<table style="clear: both; margin: 0 auto; width: 100%;" id="tblWorkCount" cellpadding="2" cellspacing="0" width="100%" border="1">
														<thead>
															<tr>
																<th class="headcol">&nbsp;</th>
															
														{foreach from=$listOperations item=op name="operations"}
																<th><a href="javascript:void(0);" title="{$op->name()}">{$smarty.foreach.operations.iteration}</a></th>
														{/foreach}
															</tr>
														</thead>

														<tbody>
														{foreach from=$operators key=operatorId item=opName}
															{assign var=showRow value=0}
															<tr id="rowOp{$operatorId}">
																<td class="headcol">{'cp1251'|iconv:'utf-8':$opName}</td>
															{foreach from=$listOperations item=op}
																
																{assign var=operationId value=$op->id()}
																{assign var="work" value=$workCount.$operatorId.$operationId}
																{assign var="price" value=$op->priceByMinutes()}
																{if $work}
																	{assign var=showRow value=1}
																{/if}
																<td>
																	<input {if !$price}disabled="disabled"{/if} type="text" size="5" name="workCount[{$operatorId}][{$operationId}][workCount]" value="{$work.workCount}" class="textWorkCount" data-currentValue="{$work.workCount}" data-operationId="{$operationId}" />
																	<input type="hidden" name="workCount[{$operatorId}][{$operationId}][workId]" value="{$work.workId}" />
																	<input type="hidden" name="workCount[{$operatorId}][{$operationId}][workCountOld]" value="{$work.workCount}" />
																	<input type="hidden" name="workCount[{$operatorId}][{$operationId}][price]" value="{$price}" />
																</td>
															{/foreach}
																
															</tr>
															{if !$showRow}
															<script type="text/javascript">$("#rowOp{$operatorId}").hide()</script>
															{else}
															<script type="text/javascript">$("#selOp{$operatorId}").hide()</script>
															{/if}
														{/foreach}
														</tbody>

														<tfoot>
															<tr>
																<td class="headcol">Общо</td>
															{foreach from=$listOperations item=op}
																{assign var=operationId value=$op->id()}
																<td id="total{$operationId}">&nbsp;{$operationsTotalCount.$operationId}</td>
															{/foreach}
															</tr>
														</tfoot>
													
													</table>
													</div>
													<input type="submit" name="saveForm" value="Запази" />
													
												</form>
											{/if}
												<br />&nbsp;
											</td>
										</tr>
										
									</table>
								
								</td>
							</tr>
						</table>


